package com.qf.java2201.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qf.java2201.common.PageVo;
import com.qf.java2201.mapper.LogisticsListMapper;
import com.qf.java2201.pojo.Logistics;
import com.qf.java2201.service.LogisticsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * ========  测试 查询    ========
 * Time: 2022/4/26
 */

@Service("logistics")
public class LogisticsServiceImpl implements LogisticsService {

    @Autowired //注入属性
    private LogisticsListMapper logisticsListMapper;

    @Override
    public PageVo<Logistics> getPageData(Map<String, Object> params) {

        String page = (String) params.get("page");
        String limit = (String) params.get("limit");

        //mybatis
        PageHelper.startPage(Integer.parseInt(page),Integer.parseInt(limit));

        List<Logistics> logistics = logisticsListMapper.selectByParams(params);

        PageInfo<Logistics> logisticsPageInfo = new PageInfo<>(logistics);

        // 把分页数据 封装到 PageVo      这个 PageVo  符合 layui 的  列表数据格式
        PageVo<Logistics> logisticsPageVo = new PageVo<>();
        logisticsPageVo.setData(logisticsPageInfo.getList());
        logisticsPageVo.setCode(0);
        logisticsPageVo.setCount(logisticsPageInfo.getTotal());
        logisticsPageVo.setMsg("物流列表数据");
        return logisticsPageVo;

    }

    //02- 添加物流信息
    @Override
    public int addLogistics(Logistics logistics) {

        return logisticsListMapper.addLogistics(logistics);
    }

    //03-编辑物流信息数据  (更新 /修改)
    @Override
    public int updateLogistics(Logistics logistics) {

        return logisticsListMapper.updateLogistics(logistics);
    }

    //04- 根据id 删除学生
    @Override
    public int deleteLogistics(Integer id) {
        return logisticsListMapper.deleteLogistics(id);
    }


 /*   @Override
    public Logistics testSelect(Integer id) {
        System.out.println("service的实现层");
        Logistics select = logisticsListMapper.select(id);
        System.out.println(select);

        return null;
    }*/

/*    @Test
    public void test1(){
        //测试查询
        ClassPathXmlApplicationContext app = new ClassPathXmlApplicationContext("applicationContext.xml");
        LogisticsService logistics = app.getBean("logistics", LogisticsService.class);

        logistics.testSelect(1);
    }*/
}
